#include "QLogin.h"
QLogin::QLogin(QWidget *parent) : QWidget(parent)
{

    this->setWindowIcon(QIcon(":/ALL/Image/ALL/Cat.png"));
    this->setWindowFlags(Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
    LabelOfVersion = new QLabel(this);
    LabelOfBackground = new QLabel(this);
    LabelOfAvatar = new QLabel(this);
    BtnOfRester = new QPushButton(this);
    BtnOfFindPsw = new QPushButton(this);
    LineeditOfAccount = new QLineEdit(this);
    LineeditOfPsw = new QLineEdit(this);
    BtnOfLogin = new QPushButton(this);
    CheckboxOfRemember = new QCheckBox(this);
    LabelOfRemember = new QLabel(this);
    CheckboxOfAuto = new QCheckBox(this);
    LabelOfAuto = new QLabel(this);
    CloseBtn = new QToolButton(this);
    MinimizeBtn = new QToolButton(this);

    QSize SizeOfLogin = QSize(538,405);
    this->setFixedSize(SizeOfLogin);
    int WidthOfAccount = (SizeOfLogin.width()-100)/2+60;
    int WidthOfRester = (SizeOfLogin.width()-100)/2-80;


    LabelOfVersion->setGeometry(0,0,SizeOfLogin.width()/3,30);
    LabelOfBackground->setGeometry(0,0,SizeOfLogin.width(),SizeOfLogin.height()-180);
    LabelOfAvatar->setGeometry(40,SizeOfLogin.height()-170,80,80);
    LineeditOfAccount->setGeometry(130,SizeOfLogin.height()-165,WidthOfAccount,30);
    LineeditOfPsw->setGeometry(130,SizeOfLogin.height()-125,WidthOfAccount,30);
    BtnOfRester->setGeometry(WidthOfAccount+100+40,SizeOfLogin.height()-165,WidthOfRester,30);
    BtnOfFindPsw->setGeometry(WidthOfAccount+100+40,SizeOfLogin.height()-125,WidthOfRester,30);
    CheckboxOfRemember->setGeometry(130,SizeOfLogin.height()-90,30,35);
    LabelOfRemember->setGeometry(150,SizeOfLogin.height()-90,100,35);
    CheckboxOfAuto->setGeometry(280,SizeOfLogin.height()-90,30,35);
    LabelOfAuto->setGeometry(300,SizeOfLogin.height()-90,100,35);
    BtnOfLogin->setGeometry(130,SizeOfLogin.height()-50,WidthOfAccount,45);
    CloseBtn->setGeometry(SizeOfLogin.width()-50,0,45,45);
    MinimizeBtn->setGeometry(SizeOfLogin.width()-80,0,45,45);

    this->setObjectName("LOGIN");
    CloseBtn->setObjectName("CloseBtn");
    MinimizeBtn->setObjectName("MinimizeBtn");
    LabelOfVersion->setObjectName("VERSION");
    LabelOfBackground->setObjectName("LOGINBG");
    LabelOfAvatar->setObjectName("Avatar");
    BtnOfRester->setObjectName("LOGINTEXT");
    BtnOfFindPsw->setObjectName("LOGINTEXT");
    BtnOfLogin->setObjectName("LOGIN");
    LineeditOfPsw->setObjectName("LOGINLINEEDIT");
    LineeditOfAccount->setObjectName("LOGINLINEEDIT");
    LabelOfAuto->setObjectName("LOGIONLABELTEXT");
    LabelOfRemember->setObjectName("LOGIONLABELTEXT");

    //头像label显示图片
    QString filename;
    if(LineeditOfAccount->text().isEmpty())
    {
        filename = QString::fromUtf8(":/Login/Image/Login/Avatar.png");
    }
    else
    {
        //如果记录了上一次的账号,此处读取上次保留的头像信息
    }
    PixmaoOfAvatar = new QPixmap(filename);
    PixmaoOfAvatar->scaled(LabelOfAvatar->size(),Qt::KeepAspectRatio);
    LabelOfAvatar->setScaledContents(true);
    LabelOfAvatar->setPixmap(*PixmaoOfAvatar);

    BtnOfRester->setText(QString::fromUtf8("注册账号"));
    BtnOfFindPsw->setText(QString::fromUtf8("忘记密码"));
    LabelOfVersion->setText(QString::fromUtf8("0.0.1.0"));
    LabelOfRemember->setText(QString::fromUtf8("记住密码"));
    LabelOfAuto->setText(QString::fromUtf8("自动登录"));
    BtnOfLogin->setText(QString::fromUtf8("登\t\t\t\t\t录"));

    LineeditOfAccount->setPlaceholderText("请输入您的账号或手机号");
    LineeditOfPsw->setPlaceholderText("请输入您的密码");
    LineeditOfPsw->setEchoMode(QLineEdit::Password);

    QReadQSS::setStyle(":/QSS/QSS/Rester.qss");

    connect(CloseBtn,SIGNAL(clicked()),this,SLOT(close()));
    connect(MinimizeBtn,&QToolButton::clicked,this,&QLogin::showMinimized);
    connect(BtnOfRester,SIGNAL(clicked()),this,SLOT(SLOTFunOfRegister()));
//    connect(BtnOfFindPsw,&QPushButton::clicked,this,&QLogin::SLOTFunOfFindPSW);
    connect(BtnOfFindPsw,SIGNAL(clicked()),this,SLOT(SLOTFunOfFindPSW()));
}

void QLogin::SLOTFunOfFindPSW()
{
    this->hide();
    QFindPSW *f = new QFindPSW;
    f->show();
    connect(f,SIGNAL(SIGNALOfGoToLogin()),this,SLOT(show()));

}

void QLogin::SLOTFunOfRegister()
{
    this->hide();
    QRegister *r = new QRegister;
    r->show();
    connect(r,SIGNAL(SIGNALOfGoToLogin()),this,SLOT(show()));
}

